const mongoose = require('mongoose');
const config = require('../src/config/config');
const { Backup } = require('../src/models');

// 连接数据库
mongoose.connect(config.mongoose.url, config.mongoose.options).then(() => {
  console.log('已连接到MongoDB');
  createTestBackup();
}).catch((err) => {
  console.error('连接MongoDB失败', err);
});

// 创建测试备份记录
const createTestBackup = async () => {
  try {
    // 检查是否已存在测试备份
    const existingBackup = await Backup.findOne({ filePath: '/backups/test_backup.zip' });
    
    if (existingBackup) {
      console.log('测试备份记录已存在:', existingBackup._id.toString());
      mongoose.disconnect();
      return;
    }
    
    // 创建新的测试备份记录
    const backup = await Backup.create({
      type: 'manual',
      fileSize: 1024, // 1KB
      status: 'success',
      filePath: '/backups/test_backup.zip',
      date: new Date(),
    });
    
    console.log('测试备份记录已创建:', backup._id.toString());
    
    // 关闭数据库连接
    mongoose.disconnect();
  } catch (error) {
    console.error('创建测试备份记录失败:', error);
    mongoose.disconnect();
  }
}; 